package edu.nf.postlikework.controller.app;

import edu.nf.postlikework.controller.BaseController;
import edu.nf.postlikework.model.dto.LikeDTO;
import edu.nf.postlikework.model.entity.User;
import edu.nf.postlikework.result.ResultVo;
import edu.nf.postlikework.service.LikeService;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author zjl
 * @date 2025/10/13
 */
@RestController
@RequiredArgsConstructor
public class LikeController extends BaseController {
    private final LikeService likeService;
    @PostMapping("/like")
    public ResultVo<?> like(Integer postId, HttpSession session){
        User user = (User)session.getAttribute("user");
        Integer userId = user!=null ? user.getUserId() :  -1;
        LikeDTO vo = likeService.like(postId, userId);
        return success(vo);
    }
}
